#!/usr/bin/env php
<?php

declare(strict_types=1);

use Phan\Issue;

require_once dirname(__DIR__) . '/src/Phan/Bootstrap.php';

call_user_func(static function () {
    $issue_groups = [
        Issue::SEVERITY_CRITICAL => [],
        Issue::SEVERITY_NORMAL => [],
        Issue::SEVERITY_LOW => [],
    ];
    foreach (Issue::issueMap() as $issue) {
        $issue_groups[$issue->getSeverity()][] = $issue->getType();
    }
    $lookup = [
        Issue::SEVERITY_CRITICAL => 'phanCritical',
        Issue::SEVERITY_NORMAL => 'phanNormal',
        Issue::SEVERITY_LOW => 'phanLow',
    ];
    echo <<<'EOT'
" These file contents should be put in .vim/syntax for the file types you wish to highlight Phan issue names in (e.g. ~/.vim/syntax/text.vim)
" The highlighted issue types don't include issue types emitted by plugins
" (generated by internal/dump_vim_highlighting.php)

EOT;
    foreach ($issue_groups as $severity => &$issues) {
        uasort($issues, 'strcmp');
        echo "syntax keyword {$lookup[$severity]} " . implode(' ', $issues) . "\n";
    }
    echo <<<'EOT'

highlight link phanCritical Error
highlight link phanNormal Todo
highlight link phanLow Comment

EOT;
});
